﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;

namespace NMA.Web
{
    // Note: For instructions on enabling IIS6 or IIS7 classic mode, 
    // visit http://go.microsoft.com/?LinkId=9394801

    using NMA.Infrastructure.NHibernate;
    using NMA.Infrastructure.Configuration;
    using NMA.Infrastructure.NHibernate.Bootstrapper;
    using NMA.Web.Core.WebRegistry;
    using NMA.Web.Core.ControllerFactory;
    using NMA.Web.Core.Helper;

    public class MvcApplication : System.Web.HttpApplication
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            RegisterRouteHelper.SetupRoutes(routes);

            routes.MapRoute(
                "Default",                                              // Route name
                "{controller}/{action}/{id}",                           // URL with parameters
                new {controller = "Home", action = "Index", id = "" }  // Parameter defaults
            );
        }

        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            RegisterRoutes(RouteTable.Routes);

            IList<Type> registries = new List<Type>();
            registries.Add(typeof(CoreRegistry));
            registries.Add(typeof(WebComponentRegistry));

            new NMA.Infrastructure.NHibernate.Bootstrapper.BootStrapper(
                registries,
                new ConfigurationManagerWrapper(),
                "NMAConnectionString",
                "NMA.Infrastructure.NHibernate", "NMA.Application", "NMA.Infrastructure.AutoMapper");

            ControllerBuilder.Current.SetControllerFactory(new StructureMapControllerFactory());
        }
    }
}